var express = require('express');
var router = express.Router();
var {reg,login,isUse,generatorToken} = require("../service/adminsService");


// 注册
router.post('/reg', async function(req, res, next) {
    const { adminName, adminPassword } = req.body;
    const data = await reg({ adminName, adminPassword });
    res.send(data);
});

// 登陆
router.get('/login', async function(req, res, next) {
  const { adminName, adminPassword } = req.query;
  const data = await login({ adminName, adminPassword });
  const result = {
    status:false
  };
  if (data.length) {
    result.status = true;
    result.token = generatorToken(adminName, adminPassword);

  }
  res.send(result);
});

// 验证用户名
router.post('/isUse', async function(req, res, next) {
    const { adminName } = req.body;
    const status = await isUse({ adminName });
    res.send(
      status
    );
});
module.exports = router;